//相交链表
public class Solution6 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        //1.分别求长度
        ListNode curA = headA;
        int lenA = 0;
        while(curA != null){
            lenA++;
            curA = curA.next;
        }
        ListNode curB = headB;
        int lenB = 0;
        while(curB != null){
            lenB++;
            curB = curB.next;
        }
        curA = headA;
        curB = headB;
        int len = lenA-lenB;
        while(len < 0){
            //修正curA和curB的指向
            curA = headB;
            curB = headA;
            len = lenB-lenA;
        }
        //代码走到这里 curA一定指向最长的，curB一定指向最短的
        //len一定是正数
        //2.最长的走差值步
        while(len != 0){
            curA = curA.next;
            len--;
        }
        //3.同时走 4.相遇的就是相遇点
        while(curA != curB){
            curA = curA.next;
            curB = curB.next;
        }
        if(curB == null){
            return null;
        }
        return curA;
    }
}